import { HasSaleAttrResponseData, SaleAttrResponseData, SkuData, SkuInfoData, SpuHasImg, SPURes, spuResponseData, TrankResponseData } from "@/types/spu";
import http from "@/utils/request";

enum API {
    //获取已有的SPU的数据
    HASSPU_URL = '/admin/product/',
    //获取全部品牌的数据
    ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
    //获取某个SPU下的全部的售卖商品的图片数据
    IMAGE_URL = '/admin/product/spuImageList/',
    //获取某一个SPU下全部的已有的销售属性接口地址
    SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
    //获取整个项目全部的销售属性[颜色、版本、尺码]
    ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
    //追加一个新的SPU
    ADDSPU_URL = '/admin/product/saveSpuInfo',
    //更新已有的SPU
    UPDATESPU_URL = '/admin/product/updateSpuInfo',
    //追加一个新增的SKU地址
    ADDSKU_URL = '/admin/product/saveSkuInfo',
    //查看某一个已有的SPU下全部售卖的商品
    SKUINFO_URL = '/admin/product/findBySpuId/',
    //删除已有的SPU
    REMOVESPU_URL = '/admin/product/deleteSpu/',
  }
//获取spu商品
export const getSpuProductAPI=(page:number,limit:number,category3Id:number)=>{
    return http<any,spuResponseData>({
        url:API.HASSPU_URL+`${page}/${limit}?category3Id=${category3Id}`
    })
}

//获取全部品牌
export const getAllTradeMarkAPI=()=>{
    return http<any,TrankResponseData>({
        url:API.ALLTRADEMARK_URL,
    })
}
// 获取某一个已有SPU全部图片的地址
export const reqSpuImageList=(spuId:number)=>{
    return http<any,SpuHasImg>({
        url:API.IMAGE_URL+spuId
    })
}

//获取所有已有销售属性
export const getHasSaleAttrAPI=(spuId:number)=>{
    return http<any ,SaleAttrResponseData>({
        url:API.SPUHASSALEATTR_URL +spuId
    })
}

//获取全部商品属性
export const getAllSaleAttrAPI=()=>{
    return http<any ,HasSaleAttrResponseData>({
        url:API.ALLSALEATTR_URL
    })
}

// 添加spu或修改spu
export const reqAddorupdateSPUAPI=(data:SPURes)=>{
   if(data.id){
    return http.post<any,any>(API.UPDATESPU_URL,data)
   }else{
    return http.post<any,any>(API.ADDSPU_URL,data)
   }
}

//添加SKU的请求方法
export const reqAddSku = (data: SkuData) =>
    http.post<any, any>(API.ADDSKU_URL, data)
  
  //获取SKU数据
  export const reqSkuList = (spuId: number | string) =>
    http.get<any, SkuInfoData>(API.SKUINFO_URL + spuId)
//删除已有的spu
export const delSPUAPI=(spuId:number)=>{
    return http<any,any>({
        url:API.REMOVESPU_URL+ `${spuId}`,
        method:'delete'
    })
}